Skip to content

Kill image workers synchronously on server shutdown - #99208

Draft
petehunt wants to merge 3 commits into
codex/sandbox-images/read-policyfrom
codex/sandbox-images/shutdown
Draft

petehunt wants to merge 3 commits into
codex/sandbox-images/read-policyfrom
codex/sandbox-images/shutdown

Conversation

@petehunt

Copy link
Copy Markdown
Contributor

Summary

Kill worker process groups synchronously on SIGINT/SIGTERM, including hung workers and workers already shutting down. Preserve custom-server signal behavior and cover cleanup with shutdown regression tests. This does not guarantee cleanup after parent SIGKILL or crashes on macOS.

Layer 5 of 6 in the sandboxed image optimization stack.

Verification

  • Final stack contents verified on macOS and Linux: image unit tests, hung-worker shutdown, and focused development/production image routes.
  • macOS config suite also passed. Intermediate layer tips were not independently rerun for publication.
  • Upstream commits were re-signed without changing any commit tree. Linux verification of the identical final tree.
  • Root type checking remains blocked by existing Octokit declaration-resolution errors in node_modules.

@petehunt
petehunt added this pull request to stack #99210 September 25, 2026 02:01
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Failing test suites

Commit: d52d47d | About building and testing Next.js

pnpm test-start-turbo test/production/next-server-nft/next-server-nft.test.ts (turbopack) (job)

  • next-server-nft > with output:standalone > should not trace too many files in next-server.js.nft.json (DD)
Expand output

● next-server-nft › with output:standalone › should not trace too many files in next-server.js.nft.json

expect(received).toMatchInlineSnapshot(snapshot)

Snapshot name: `next-server-nft with output:standalone should not trace too many files in next-server.js.nft.json 1`

- Snapshot  -    0
+ Received  + 2996

@@ -5,108 +5,3024 @@
    "/node_modules/@img/sharp-libvips-<PLATFORM>-<ARCH>/*",
    "/node_modules/@next/env/*",
    "/node_modules/@swc/helpers/*",
    "/node_modules/client-only/*",
    "/node_modules/detect-libc/*",
+   "/node_modules/next/AGENTS.md",
+   "/node_modules/next/README.md",
+   "/node_modules/next/app.js",
+   "/node_modules/next/babel.js",
+   "/node_modules/next/cache.js",
+   "/node_modules/next/client.js",
+   "/node_modules/next/compat/router.js",
+   "/node_modules/next/constants.js",
+   "/node_modules/next/dist/agent-feedback/protocol.md",
+   "/node_modules/next/dist/api/app-dynamic.js",
+   "/node_modules/next/dist/api/app.js",
+   "/node_modules/next/dist/api/constants.js",
+   "/node_modules/next/dist/api/document.js",
+   "/node_modules/next/dist/api/dynamic.js",
+   "/node_modules/next/dist/api/error.js",
+   "/node_modules/next/dist/api/error.react-server.js",
+   "/node_modules/next/dist/api/form.js",
+   "/node_modules/next/dist/api/head.js",
+   "/node_modules/next/dist/api/headers.js",
+   "/node_modules/next/dist/api/image.js",
+   "/node_modules/next/dist/api/link.js",
+   "/node_modules/next/dist/api/navigation.js",
+   "/node_modules/next/dist/api/navigation.react-server.js",
+   "/node_modules/next/dist/api/og.js",
+   "/node_modules/next/dist/api/router.js",
+   "/node_modules/next/dist/api/script.js",
+   "/node_modules/next/dist/api/server.js",
+   "/node_modules/next/dist/bin/next",
+   "/node_modules/next/dist/build/adapter/build-complete.js",
+   "/node_modules/next/dist/build/adapter/fallback-shell-runs.js",
    "/node_modules/next/dist/build/adapter/setup-node-env.external.js",
+   "/node_modules/next/dist/build/adapter/synthetic-symlinks.js",
+   "/node_modules/next/dist/build/after-production-compile.js",
+   "/node_modules/next/dist/build/analysis/extract-const-value.js",
+   "/node_modules/next/dist/build/analysis/get-page-static-info.js",
+   "/node_modules/next/dist/build/analysis/parse-module.js",
+   "/node_modules/next/dist/build/analyze/index.js",
+   "/node_modules/next/dist/build/analyze/snapshot.js",
+   "/node_modules/next/dist/build/babel/loader/get-config.js",
+   "/node_modules/next/dist/build/babel/loader/index.js",
+   "/node_modules/next/dist/build/babel/loader/transform.js",
+   "/node_modules/next/dist/build/babel/loader/util.js",
+   "/node_modules/next/dist/build/babel/plugins/commonjs.js",
+   "/node_modules/next/dist/build/babel/plugins/jsx-pragma.js",
+   "/node_modules/next/dist/build/babel/plugins/next-font-unsupported.js",
+   "/node_modules/next/dist/build/babel/plugins/next-page-config.js",
+   "/node_modules/next/dist/build/babel/plugins/next-page-disallow-re-export-all-exports.js",
+   "/node_modules/next/dist/build/babel/plugins/next-ssg-transform.js",
+   "/node_modules/next/dist/build/babel/plugins/optimize-hook-destructuring.js",
+   "/node_modules/next/dist/build/babel/plugins/react-loadable-plugin.js",
+   "/node_modules/next/dist/build/babel/preset.js",
+   "/node_modules/next/dist/build/browser-variant-modules.js",
+   "/node_modules/next/dist/build/build-context.js",
+   "/node_modules/next/dist/build/collect-build-traces.js",
+   "/node_modules/next/dist/build/compiler.js",
+   "/node_modules/next/dist/build/create-compiler-aliases.js",
    "/node_modules/next/dist/build/define-env.js",
    "/node_modules/next/dist/build/duration-to-string.js",
+   "/node_modules/next/dist/build/entries.js",
+   "/node_modules/next/dist/build/file-classifier.js",
+   "/node_modules/next/dist/build/generate-build-id.js",
+   "/node_modules/next/dist/build/generate-routes-manifest.js",
+   "/node_modules/next/dist/build/get-babel-config-file.js",
+   "/node_modules/next/dist/build/get-babel-loader-config.js",
+   "/node_modules/next/dist/build/get-convention-file-base-name.js",
+   "/node_modules/next/dist/build/get-static-info-including-layouts.js",
    "/node_modules/next/dist/build/get-supported-browsers.js",
+   "/node_modules/next/dist/build/handle-entrypoints.js",
+   "/node_modules/next/dist/build/handle-externals.js",
+   "/node_modules/next/dist/build/index.js",
+   "/node_modules/next/dist/build/is-writeable.js",
+   "/node_modules/next/dist/build/jest/__mocks__/empty.js",
+   "/node_modules/next/dist/build/jest/__mocks__/fileMock.js",
+   "/node_modules/next/dist/build/jest/__mocks__/nextFontMock.js",
+   "/node_modules/next/dist/build/jest/__mocks__/styleMock.js",
+   "/node_modules/next/dist/build/jest/jest.js",
+   "/node_modules/next/dist/build/jest/object-proxy.js",
+   "/node_modules/next/dist/build/load-entrypoint.js",
+   "/node_modules/next/dist/build/load-jsconfig.js",
+   "/node_modules/next/dist/build/lockfile.js",
+   "/node_modules/next/dist/build/manifests/formatter/format-manifest.js",
    "/node_modules/next/dist/build/next-config-ts/require-hook.js",
    "/node_modules/next/dist/build/next-config-ts/transpile-config.js",
+   "/node_modules/next/dist/build/next-dir-paths.js",
    "/node_modules/next/dist/build/nft.js",
+   "/node_modules/next/dist/build/normalize-catchall-routes.js",
    "/node_modules/next/dist/build/output/format.js",
+   "/node_modules/next/dist/build/output/index.js",
    "/node_modules/next/dist/build/output/log.js",
+   "/node_modules/next/dist/build/output/store.js",
+   "/node_modules/next/dist/build/page-extensions-type.js",
+   "/node_modules/next/dist/build/polyfills/fetch/index.js",
+   "/node_modules/next/dist/build/polyfills/fetch/whatwg-fetch.js",
+   "/node_modules/next/dist/build/polyfills/object-assign.js",
+   "/node_modules/next/dist/build/polyfills/object.assign/auto.js",
+   "/node_modules/next/dist/build/polyfills/object.assign/implementation.js",
+   "/node_modules/next/dist/build/polyfills/object.assign/index.js",
+   "/node_modules/next/dist/build/polyfills/object.assign/polyfill.js",
+   "/node_modules/next/dist/build/polyfills/object.assign/shim.js",
+   "/node_modules/next/dist/build/polyfills/polyfill-module.js",
+   "/node_modules/next/dist/build/polyfills/polyfill-nomodule.js",
+   "/node_modules/next/dist/build/polyfills/process.js",
+   "/node_modules/next/dist/build/preview-key-utils.js",
+   "/node_modules/next/dist/build/print-build-errors.js",
+   "/node_modules/next/dist/build/progress.js",
+   "/node_modules/next/dist/build/rendering-mode.js",
+   "/node_modules/next/dist/build/route-bundle-stats.js",
+   "/node_modules/next/dist/build/route-discovery.js",
    "/node_modules/next/dist/build/segment-config/app/app-segment-config.js",
    "/node_modules/next/dist/build/segment-config/app/app-segments.js",
    "/node_modules/next/dist/build/segment-config/app/collect-root-param-keys.js",
+   "/node_modules/next/dist/build/segment-config/middleware/middleware-config.js",
+   "/node_modules/next/dist/build/segment-config/pages/pages-segment-config.js",
+   "/node_modules/next/dist/build/sort-by-page-exts.js",
+   "/node_modules/next/dist/build/spinner.js",
    "/node_modules/next/dist/build/static-paths/app.js",
    "/node_modules/next/dist/build/static-paths/app/extract-pathname-route-param-segments-from-loader-tree.js",
    "/node_modules/next/dist/build/static-paths/pages.js",
+   "/node_modules/next/dist/build/static-paths/types.js",
    "/node_modules/next/dist/build/static-paths/utils.js",
    "/node_modules/next/dist/build/swc/helpers.js",
    "/node_modules/next/dist/build/swc/index.js",
    "/node_modules/next/dist/build/swc/install-bindings.js",
    "/node_modules/next/dist/build/swc/jest-transformer.js",
    "/node_modules/next/dist/build/swc/loaderWorkerPool.js",
    "/node_modules/next/dist/build/swc/options.js",
    "/node_modules/next/dist/build/swc/types.js",
+   "/node_modules/next/dist/build/templates/app-page-runtime.js",
+   "/node_modules/next/dist/build/templates/app-page.js",
+   "/node_modules/next/dist/build/templates/app-route.js",
+   "/node_modules/next/dist/build/templates/edge-app-route.js",
+   "/node_modules/next/dist/build/templates/edge-ssr-app.js",
+   "/node_modules/next/dist/build/templates/edge-ssr.js",
+   "/node_modules/next/dist/build/templates/edge-wrapper.js",
+   "/node_modules/next/dist/build/templates/helpers.js",
+   "/node_modules/next/dist/build/templates/middleware.js",
+   "/node_modules/next/dist/build/templates/pages-api.js",
+   "/node_modules/next/dist/build/templates/pages-edge-api.js",
+   "/node_modules/next/dist/build/templates/pages.js",
+   "/node_modules/next/dist/build/turbopack-analyze/index.js",
+   "/node_modules/next/dist/build/turbopack-build/impl.js",
+   "/node_modules/next/dist/build/turbopack-build/index.js",
+   "/node_modules/next/dist/build/turborepo-access-trace/env.js",
+   "/node_modules/next/dist/build/turborepo-access-trace/helpers.js",
+   "/node_modules/next/dist/build/turborepo-access-trace/index.js",
+   "/node_modules/next/dist/build/turborepo-access-trace/result.js",
+   "/node_modules/next/dist/build/turborepo-access-trace/tcp.js",
+   "/node_modules/next/dist/build/turborepo-access-trace/types.js",
+   "/node_modules/next/dist/build/type-check.js",
    "/node_modules/next/dist/build/utils.js",
+   "/node_modules/next/dist/build/validate-app-paths.js",
+   "/node_modules/next/dist/build/warn-about-edge-runtime.js",
+   "/node_modules/next/dist/build/webpack-build/impl.js",
+   "/node_modules/next/dist/build/webpack-build/index.js",
+   "/node_modules/next/dist/build/webpack-config-rules/resolve.js",
+   "/node_modules/next/dist/build/webpack-config.js",
+   "/node_modules/next/dist/build/webpack/alias/react-dom-server-experimental.js",
+   "/node_modules/next/dist/build/webpack/alias/react-dom-server.js",
+   "/node_modules/next/dist/build/webpack/cache-invalidation.js",
+   "/node_modules/next/dist/build/webpack/config/blocks/base.js",
+   "/node_modules/next/dist/build/webpack/config/blocks/css/index.js",
+   "/node_modules/next/dist/build/webpack/config/blocks/css/loaders/client.js",
+   "/node_modules/next/dist/build/webpack/config/blocks/css/loaders/file-resolve.js",
+   "/node_modules/next/dist/build/webpack/config/blocks/css/loaders/getCssModuleLocalIdent.js",
+   "/node_modules/next/dist/build/webpack/config/blocks/css/loaders/global.js",
+   "/node_modules/next/dist/build/webpack/config/blocks/css/loaders/index.js",
+   "/node_modules/next/dist/build/webpack/config/blocks/css/loaders/modules.js",
+   "/node_modules/next/dist/build/webpack/config/blocks/css/loaders/next-font.js",
+   "/node_modules/next/dist/build/webpack/config/blocks/css/messages.js",
+   "/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js",
+   "/node_modules/next/dist/build/webpack/config/blocks/images/index.js",
+   "/node_modules/next/dist/build/webpack/config/blocks/images/messages.js",
+   "/node_modules/next/dist/build/webpack/config/helpers.js",
+   "/node_modules/next/dist/build/webpack/config/index.js",
+   "/node_modules/next/dist/build/webpack/config/utils.js",
+   "/node_modules/next/dist/bu

... truncated ...

pnpm test-start-turbo test/production/pnpm-support/index.test.ts (turbopack) (job)

  • pnpm support > build with dependencies installed via pnpm > should build with dependencies installed via pnpm (DD)
Expand output

● pnpm support › build with dependencies installed via pnpm › should build with dependencies installed via pnpm

expect(received).toBe(expected) // Object.is equality

Expected: false
Received: true

  47 |         try {
  48 |           matchingFile = manifest.files.some((file) => file.includes(ignore))
> 49 |           expect(!!matchingFile).toBe(false)
     |                                  ^
  50 |         } catch (err) {
  51 |           require('console').error(
  52 |             `Found unexpected file in manifest ${matchingFile} matched ${ignore}`

  at Object.toBe (production/pnpm-support/index.test.ts:49:34)

@petehunt
petehunt force-pushed the codex/sandbox-images/shutdown branch from a6ce6e2 to 9d061e3 Compare September 25, 2026 20:52
@petehunt
petehunt force-pushed the codex/sandbox-images/shutdown branch from 9d061e3 to 462cec9 Compare September 29, 2026 15:40
@petehunt
petehunt force-pushed the codex/sandbox-images/shutdown branch 3 times, most recently from 3806afd to b55722c Compare September 29, 2026 19:21
@petehunt
petehunt force-pushed the codex/sandbox-images/shutdown branch from b55722c to d52d47d Compare September 29, 2026 21:00

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant